﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Ahi.Controller
{
    public class KriterUreticiController
    {
        private DevExpress.XtraGrid.Views.Grid.GridView gridView;

        public KriterUreticiController(DevExpress.XtraGrid.Views.Grid.GridView gridView)
        {
            this.gridView = gridView;
        }

        public List<ISorgulanabilir> Uret(Type T)
        {
            List<ISorgulanabilir> result = new List<ISorgulanabilir>();
            try
            {
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(T);

                foreach (PropertyDescriptor item in properties)
                {
                    if (item.Name == "Id" || item.IsReadOnly || !item.IsBrowsable)
                        continue;
                    else
                    {
                        if (item.PropertyType.IsGenericType)
                            result.AddRange(Uret(item.PropertyType.GetGenericArguments()[0]));
                        else
                            result.Add(new GenericSorgulanabiliEntity { Isim = item.Name, SorgulamaKriteri = Entity.Enums.SorgulamaKriterleri.Onemsiz });
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }

    public class GenericSorgulanabiliEntity : ISorgulanabilir
    {
        #region ISorgulanabilir Members

        public string Isim
        {
            get;
            set;
        }

        public Entity.Enums.SorgulamaKriterleri SorgulamaKriteri
        {
            get;
            set;
        }

        public object Deger
        {
            get;
            set;
        }

        #endregion
    }
}
